﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessComponents.Common;

namespace BusinessComponents.DomainModels
{
    public class RoomList
    {
        WaterFrontEntities wfe = new WaterFrontEntities();

        public ViewRoom InitFromRoom(Room roomItem)
        {
            ViewRoom roomView = new ViewRoom();
            roomView.RoomNo = roomItem.RoomNo;
            roomView.Status = roomItem.Status;
            if (roomItem.Status == 1)
            {
                roomView.RoomStatus = "Open";
            }
            else
            {
                roomView.RoomStatus = "Locked";
            }
            roomView.TypeCode = roomItem.TypeCode;
            roomView.Description = roomItem.RoomType.Description;
            roomView.Remarks = roomItem.Remarks;
            roomView.StdPrice = roomItem.RoomType.StdPrice;
            roomView.MaxOccupant = roomItem.RoomType.MaxOccupant;
            roomView.CreatedDateTime = (DateTime)roomItem.CreatedDateTime;

            return roomView;
        }

        public List<ViewRoom> SearchRoom(int roomType, int roomStatus, string roomNum)
        {
            List<ViewRoom> roomList = new List<ViewRoom>();
            ViewRoom tempView;

            foreach (var item in wfe.Rooms)
            {
                if (!String.IsNullOrEmpty(roomNum))
                {
                    if (item.RoomNo == roomNum)
                    {
                        tempView = InitFromRoom(item);
                        roomList.Add(tempView);
                    }
                }
                else
                {
                    if (roomStatus == -1 )
                    {
                        if (item.TypeCode == roomType || roomType == 0)
                        {
                            tempView = InitFromRoom(item);
                            roomList.Add(tempView);
                        }
                    }
                    else
                    {
                        if (item.Status == roomStatus && (item.TypeCode == roomType || roomType == 0))
                        {
                            tempView = InitFromRoom(item);
                            roomList.Add(tempView);
                        }
                    }
                }
            }
            return roomList;
        }
    }

    public class ViewRoom
    {
        public string RoomNo { get; set; }
        public int TypeCode { get; set; }
        public string Description { get; set; }
        public string RoomStatus { get; set; }
        public int Status { get; set; }
        public DateTime CreatedDateTime { get; set; }
        public int MaxOccupant { get; set; }
        public int StdPrice { get; set; }
        public string Remarks { get; set; }
        public string PriceInDollar
        {
            get
            {
                return FinanceUtils.centToDollar(StdPrice);
            }

            set
            {
            }
        }
    }
}
